body {
    margin: 0;
    font-family: 'Arial', sans-serif;
    background-color: #252836; /* Dark slate grey background */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #f0f0f0;
    overflow: hidden; /* Prevent body scroll from menu overflows */
}

#root {
    width: 100%;
    height: 100vh; /* Full viewport height */
    max-width: 1200px; /* Max width for the app content */
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    background-color: #444; /* Slightly lighter dark background for the app */
    border-radius: 8px;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* ======= NEW TOP POUOUT MENU STYLES ======= */
.menu-toggle-top {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    background-color: rgba(47, 56, 79, 0.85);
    border: 1px solid #5F6B8C;
    border-radius: 50%; /* Make it round for an icon */
    padding: 12px; /* Sufficient for the hamburger lines */
    width: 48px; /* Fixed width */
    height: 48px; /* Fixed height */
    display: flex; /* For centering the span */
    justify-content: center; /* For centering the span */
    align-items: center; /* For centering the span */
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: background-color 0.2s;
}

.menu-toggle-top span {
    display: block;
    width: 22px;
    height: 3px;
    background-color: white;
    position: relative;
    border-radius: 3px;
}

.menu-toggle-top span::before,
.menu-toggle-top span::after {
    content: '';
    display: block;
    width: 22px;
    height: 3px;
    background-color: white;
    position: absolute;
    border-radius: 3px;
    transition: transform 0.3s ease;
}

.menu-toggle-top span::before {
    top: -6px;
}

.menu-toggle-top span::after {
    top: 6px;
}

.menu-toggle-top.open span::before {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle-top.open span::after {
    transform: rotate(-45deg) translate(5px, -5px);
}

.menu-toggle-top.open span {
    background-color: transparent;
}

.menu-toggle-top:hover {
    background-color: #5D148C;
}

.top-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    background-color: rgba(34, 40, 49, 0.95); /* Dark slate grey with transparency */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    transform: translateY(-100%);
    transition: transform 0.3s ease-out;
    z-index: 25;
    border-bottom: 1px solid #5F6B8C;
}

.top-toolbar.open {
    transform: translateY(0);
}

.top-toolbar button, .menu button {
    background-color: rgba(47, 56, 79, 0.85); /* Slate grey */
    color: white;
    border: 1px solid #5F6B8C; /* Outline */
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.9em;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    min-width: 100px;
    gap: 5px;
}

.top-toolbar button img, .menu button img {
    width: 30px; /* Big icons */
    height: 30px;
    filter: brightness(1) invert(0) opacity(0.9); /* Keep icons consistent */
}

.top-toolbar button:hover:not(:disabled) {
    background-color: #4477EE;
}

.top-toolbar button:active:not(:disabled) {
    transform: translateY(1px);
}

.top-toolbar button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.menu {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 250px; /* Fixed width for menus */
    background-color: rgba(34, 40, 49, 0.9); /* Semi-transparent dark slate */
    backdrop-filter: blur(8px); /* Glass effect */
    padding: 20px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease-out;
    z-index: 20;
    overflow-y: auto; /* Allow scrolling for many colors/tools */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.right-menu {
    right: 0;
    transform: translateX(100%);
    border-top-left-radius: 15px;
    border-bottom-left-radius: 15px;
    border-right: 1px solid #5F6B8C;
}

.right-menu.open {
    transform: translateX(0);
}

.menu h3, .menu h4 {
    color: white;
    text-align: center;
    margin: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

/* New styles for bottom color palette */
.bottom-color-palette {
    width: 100%;
    padding: 10px;
    background-color: rgba(34, 40, 49, 0.95);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.5);
    z-index: 20; /* Below tool menus, above main content */
    display: flex;
    flex-direction: column; /* Stack rows vertically */
    gap: 5px; /* Gap between color rows */
    align-items: center; /* Center color rows horizontally */
    border-top: 1px solid #5F6B8C;

    /* Positioning and animation for hiding/showing */
    position: fixed;
    bottom: 0;
    left: 0;
    transform: translateY(100%); /* Initially hide it below the screen */
    transition: transform 0.3s ease-out;
}

.bottom-color-palette.open {
    transform: translateY(0); /* Slide up when open */
}

.color-palette-row {
    display: flex;
    flex-wrap: wrap; /* Allow colors to wrap if too many for one line */
    justify-content: center; /* Center colors within the row */
    gap: 4px; /* Gap between individual color swatches */
    width: 100%; /* Take full width */
}

/* Remove old color palette grid */
.color-palette-grid {
    display: none;
}

.color-swatch {
  height: 25px; /* Slightly larger swatches */
  width: 25px; /* Make them square */
  min-height: unset; /* Override existing min-height */
  min-width: unset; /* Override existing min-width */
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s;
  display: flex;
  flex-shrink: 0; /* Prevent swatches from shrinking in flex container */
}

.color-swatch:hover {
  transform: scale(1.1);
  z-index: 2;
}

.color-swatch.selected {
  border: 2px solid white;
  box-shadow: 0 0 0 1px black;
}

/* Remove old color picker */
.rainbow-gradient-picker {
    display: none;
}

.magic-button {
    display: none;
}

.tool-button img {
    filter: brightness(0) invert(1);
}

.tool-button.selected {
    border: 2px solid #6699FF;
    background-color: rgba(34, 40, 49, 0.95);
    color: #333;
}

.tool-button.selected img {
    filter: brightness(1) invert(0) opacity(1);
}

.brush-size-options, .brush-texture-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.3);
}

.brush-size-options .brush-size-buttons,
.brush-texture-options .brush-texture-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.brush-size-options .tool-button,
.brush-texture-options .tool-button {
    flex-grow: 1; /* Allow buttons to grow to fill space */
    min-width: unset; /* Override min-width from general tool-button */
    padding: 8px 12px;
    font-size: 0.9em;
}

/* Menu Toggle Buttons */
.menu-toggle-right, .menu-toggle-left {
    position: absolute; /* Changed from fixed to absolute within main-content */
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(47, 56, 79, 0.85);
    color: white;
    border: 1px solid #5F6B8C;
    padding: 15px;
    font-size: 1.3em;
    cursor: pointer;
    z-index: 25;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: background-color 0.2s, transform 0.2s;
}

.menu-toggle-right {
    right: 10px;
    border-radius: 50% 0 0 50%; /* Half circle shape */
}

.menu-toggle-right:hover {
    background-color: #5D148C;
    transform: translateY(-50%) translateX(-5px);
}

.menu-toggle-left {
    left: 10px;
    border-radius: 0 50% 50% 0; /* Half circle shape for left */
}

.menu-toggle-left:hover {
    background-color: #5D148C;
    transform: translateY(-50%) translateX(5px);
}

.menu-toggle-left img {
    width: 30px;
    height: 30px;
    filter: brightness(0) invert(1); /* Default white icon */
}

.menu-toggle-left.selected {
    border: 2px solid #6699FF;
    background-color: rgba(34, 40, 49, 0.95);
    color: #333;
}

.menu-toggle-left.selected img {
    filter: brightness(1) invert(0) opacity(1); /* Color icon when selected */
}

/* Settings Panel */
.settings-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.settings-panel {
    background-color: rgba(34, 40, 49, 0.95);
    border: 1px solid #5F6B8C;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 300px;
    text-align: center;
}

.settings-panel h2 {
    color: white;
    margin-top: 0;
}

.settings-panel label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 1.2em;
    color: #f0f0f0;
}

.settings-panel input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #6699FF; /* Accent color for checkboxes */
}

.settings-panel button {
    background-color: #FF6600; /* Orange for settings buttons */
    margin-top: 10px;
}

.settings-panel button:hover {
    background-color: #EE5500;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .top-toolbar {
        padding: 8px;
        gap: 5px;
    }
    
    .top-toolbar button {
        padding: 5px 10px;
        min-width: 80px;
        font-size: 0.8em;
    }
    
    .menu-toggle-top {
        padding: 8px 15px;
        font-size: 0.9em;
    }
}

@media (max-width: 480px) {
    .top-toolbar {
        flex-direction: column;
        align-items: center;
        padding: 5px;
    }
    
    .top-toolbar button {
        width: 90%;
        padding: 4px 8px;
    }
    
    .menu-toggle-top {
        padding: 6px 12px;
        font-size: 0.8em;
    }
}

/* Adjust main content to account for menu space */
.main-content {
    display: flex;
    flex: 1; /* Take all available vertical space */
    position: relative;
    background-color: #555;
    margin-top: 10px;
    padding-top: 5px;
}

/* Push canvas down slightly to center better */
.canvas-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #FFFFFF; /* White canvas */
    border: 3px solid #3A4055;
    margin: 10px;
    border-radius: 10px;
    overflow: hidden; /* Ensure SVG doesn't overflow its container */
}

.svg-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.base-svg, .lines-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.base-svg {
    z-index: 1;
}

.brush-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2; /* Brush strokes above base fill, below lines */
    pointer-events: all;
}

.lines-svg {
    z-index: 3; /* Lines are always on top */
    pointer-events: none; /* Make lines layer unclickable */
}

.base-svg svg {
    pointer-events: auto; /* Allow interaction with elements inside this SVG for fill tool */
}

.svg-container svg {
    max-width: 100%;
    max-height: 100%;
    display: block; /* Remove extra space below SVG */
    touch-action: none; /* Disable default touch actions for better custom handling */
}

.rainbow-category {
    width: 100%;
    margin-bottom: 15px;
}